(function() {
    'use strict';
    var icons = [{
        name: "home",
        cn: "首页",
        data: [
            "assets/images/home999999.png",
            "assets/images/homeFE7B05.png",
            "assets/images/home1CC752.png",
            "assets/images/home282828.png",
            "assets/images/home3388FF.png",
            "assets/images/home834232.png",
            "assets/images/home8F44AD.png",
            "assets/images/homeFF443A.png",
            "assets/images/homeFFFFFF.png",
            "assets/images/home000.png",
            "assets/images/home001.png",
        ]
    }, {
        name: "cart",
        cn: "购物车",
        data: [
            "assets/images/cart999999.png",
            "assets/images/cartFE7B05.png",
            "assets/images/cart1CC752.png",
            "assets/images/cart282828.png",
            "assets/images/cart3388FF.png",
            "assets/images/cart834232.png",
            "assets/images/cart8F44AD.png",
            "assets/images/cartFF443A.png",
            "assets/images/cartFFFFFF.png",
            "assets/images/cart000.png",
            "assets/images/cart001.png",
        ]
    }, {
        name: "my",
        cn: "我的",
        data: [
            "assets/images/my999999.png",
            "assets/images/myFE7B05.png",
            "assets/images/my1CC752.png",
            "assets/images/my282828.png",
            "assets/images/my3388FF.png",
            "assets/images/my834232.png",
            "assets/images/my8F44AD.png",
            "assets/images/myFF443A.png",
            "assets/images/myFFFFFF.png",
            "assets/images/my000.png",
            "assets/images/my001.png",
        ]
    }, {
        name: "order",
        cn: "订单",
        data: [
            "assets/images/order999999.png",
            "assets/images/orderFE7B05.png",
            "assets/images/order1CC752.png",
            "assets/images/order282828.png",
            "assets/images/order3388FF.png",
            "assets/images/order834232.png",
            "assets/images/order8F44AD.png",
            "assets/images/orderFF443A.png",
            "assets/images/orderFFFFFF.png",
        ]
    }, {
        name: "pro",
        cn: "多人",
        data: [
            "assets/images/pro999999.png",
            "assets/images/proFE7B05.png",
            "assets/images/pro1CC752.png",
            "assets/images/pro282828.png",
            "assets/images/pro3388FF.png",
            "assets/images/pro834232.png",
            "assets/images/pro8F44AD.png",
            "assets/images/proFF443A.png",
            "assets/images/proFFFFFF.png",
        ]
    }, {
        name: "cat",
        cn: "cat",
        data: [
            "assets/images/cat00A99E.png",
            "assets/images/cat1CC752.png",
            "assets/images/cat8F44AD.png",
            "assets/images/cat3388FF.png",
            "assets/images/cat282828.png",
            "assets/images/cat834232.png",
            "assets/images/cat999999.png",
            "assets/images/catFE7B05.png",
            "assets/images/catFF443A.png",
            "assets/images/catFFFFFF.png",
        ]
    }]
    angular.module('webApp')
        .run(["$templateCache", "dataService",
            function($templateCache, dataService) {
                var tplName = "views/directives.bottomicon.html";
                dataService.tpl(tplName).then(function(html) {
                    $templateCache.put(tplName, html);
                });
            }
        ])
        .directive('bottomIcon', ["$rootScope", "helper", function($rootScope, helper) {
            return {
                restrict: 'E',
                template: "<img ng-src='{{index==0?ngModel.selectedIconPath:ngModel.iconPath}}' style='height:30px;margin-left:14px;' ng-click='show()' />",
                replace: true,
                require: 'ngModel',
                scope: {
                    ngModel: "=",
                    index: "@",
                    callback: "&", //确认回调函数
                },
                controller: ['$scope', 'authService', 'sessionService', 'dataService', '$compile', 'helper', '$templateCache', 'base64', '$timeout', 'ERP_CONFIG', function($scope, authService, sessionService, dataService, $compile, helper, $templateCache, base64, $timeout, ERP_CONFIG) {
                    // $scope.data = {
                    //     "color": "#999999",
                    //     "selectedColor": "#479de6",
                    //     "borderStyle": "#f3f3f3",
                    //     "backgroundColor": "#fff",
                    // };
                    if ($scope.index == 0) {
                        $scope.addtype = "selectedIconPath";
                    } else {
                        $scope.addtype = "iconPath";
                    }
                    $scope.title = $scope.title || "按钮";
                    $scope.icons = icons;
                    $scope.tabid = -1;
                    //                     console.error("11111111",$scope.ngModel);

                    $scope.show = function() {
                        //console.error("11111", $scope.ngModel.tabBar, $scope.ngModel.topBar);
                        //弹出
                        _.map($scope.icons, function(icon, index) {
                            if ($scope.ngModel.iconPath.indexOf(icon.name) != -1) {
                                console.error("index", index);
                                $scope.tabid = index + 1;
                            }
                        })
                        $scope.setIconType = function(type) {
                            $scope.addtype = type;
                        }
                        $scope.setIcon = function(icon) {
                            $scope.ngModel[$scope.addtype] = icon;
                        }
                        $scope.loginWin = $.alert({
                            backdrop: "static",
                            keyboard: false,
                            title: '<span>{{"底部按钮设置"|translate}}</span>',
                            body: $templateCache.get("views/directives.bottomicon.html"),
                            okBtn: '{{"确认"|translate}}',
                            closeBtn: true,
                            hasfoot: true,
                            transition: true,
                            width: '600',
                            height: '180',
                            show: function(e) {
                                $compile($(e.currentTarget).contents())($scope);
                            },
                            okHide: function(e) {
                                // $scope.callback({ tabbar: $scope.ngModel });
                            },
                            shown: function(e) {

                            }
                        });
                    }


                }],

                link: function(scope, elem, attrs, ctrl) {
                    //初始化，获取数据
                    ctrl.$render = function() {
                        if (ctrl.$viewValue && ctrl.$viewValue.topBar && ctrl.$viewValue.tabBar) {
                            // console.error(111111, ctrl.$viewValue)
                            ctrl.$setViewValue(ctrl.$viewValue);
                        }
                    };
                }
            }
        }]);
})();